home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / WORLDSRC.ZIP / HELPER.C < prev    next >
C/C++ Source or Header  |  1992-08-13  |  28KB  |  1,188 lines

  1. #define EXTERN extern
  2.  
  3. #include <stdio.h>
  4. #include "parame.inc"
  5. #include "variab.h"
  6. #include "arrays.h"
  7. #include "qtext.inc"
  8.  
  9. #define Q1TEXT "q1text.dat"
  10.  
  11. /* World C Version 1.00 copyright 1987 J.D.McDonald 
  12.    Use as you like for non-commercial purposes, but please
  13.    leave this note, and document any changes you make as yours */
  14.  
  15. static int      start = 0;
  16. int             q1text_dat;
  17. static int      debugflg = 1;
  18. static char     filenm[] = "world.sav";
  19.  
  20. static short    buffer[512];
  21. static long     filepos, oldpos;
  22.      
  23.  
  24. speak(point)
  25.     int             point;
  26. {
  27.     /* 
  28.      * this is the main routine to output text from the data file the word
  29.      * rtext(point) points to the proper record in the file  
  30.      */
  31.     int             i, bi, t, kk;
  32.     long            z;
  33.  
  34.     if (start == 0) {
  35.     start += 1;
  36.     oldpos = -1;
  37.     q1text_dat = open(Q1TEXT, 0);
  38.         if(q1text_dat == -1) {
  39.             printf("Can't open text file q1text.dat.\n");
  40.             exit(0);
  41.         }
  42.     }
  43.     z = (long) ((unsigned long) rtext[point]);
  44.     filepos = z * 2 & ~1023l;
  45.     if (filepos != oldpos) {
  46.     oldpos = filepos;
  47.     lseek(q1text_dat, filepos, 0);
  48.     read(q1text_dat, buffer, 512*sizeof(short));
  49.     }
  50.     bi = z & 511;
  51.     do {
  52.     kk = 0;
  53.     while (1) {
  54.         if (bi == 512) {
  55.         oldpos += 1024;
  56.         lseek(q1text_dat, oldpos, 0);
  57.         read(q1text_dat, buffer, 512*sizeof(short));
  58.         bi = 0;
  59.         }
  60.         t = buffer[bi];
  61.             z++;
  62.             bi++;
  63.  
  64.         if (t < 0) {
  65.         t = -t;
  66.         outst2[kk++] = t & 127;
  67.         outst2[kk++] = t >> 8;
  68.         } else {
  69.         outst2[kk++] = (t % 32) + 96;
  70.         outst2[kk++] = ((t >> 5) % 32) + 96;
  71.         outst2[kk++] = t / 1024 + 96;
  72.         if (outst2[kk - 3] == '{') {
  73.             kmax = kk - 4;
  74.                 break;
  75.         } 
  76.         }
  77.         if (outst2[kk - 2] == '{') {
  78.                 kmax = kk - 3;
  79.         break;
  80.         } else if (outst2[kk - 1] == '{') {
  81.             kmax = kk - 2;
  82.         break;
  83.         }
  84.     }
  85.     for (i = 0; i <= kmax; i++) {
  86.         if (outst2[i] == '`')
  87.         outst2[i] = ' ';
  88.         if (outst2[i] == '|')
  89.         outst2[i] = '.';
  90.     }
  91.     if (wwflag == 0)
  92.         linout(outst2, kmax + 1);
  93.     } while (z < (long) ( (unsigned long) rtext[point + 1] ) );
  94. }
  95.  
  96. vlocat(i, h)
  97.     int             i, h;
  98. {
  99.     int             k, p, r, nowir, xloc, xturn;
  100.     /*
  101.      * code for "l" or "locate"  but NOT "look" gtext(2) points to short
  102.      * descriptions in the location area of the text file, while gtext(1)
  103.      * points to the long ones  
  104.      */
  105.  
  106.     if (brfflg == 2 || i == 1 || ((locdat[loc] & 16384) == 0
  107.                   && brfflg != 0) || (loc >= 101 && loc <= 116))
  108.     xloc = loc + gtext[1];
  109.     else
  110.     xloc = loc + gtext[2];
  111.     speak(xloc);
  112.     if (loc == 89) {
  113.     if (easttm == 0) {
  114.         speak(372);
  115.         eastsc |= 1;
  116.     } else if (easttm > 0 && easttm <= 50) {
  117.         speak(373);
  118.         eastsc |= 2;
  119.     } else if (easttm == 51)
  120.         speak(374);
  121.     else {
  122.         speak(375);
  123.         eastsc |= 4;
  124.     }
  125.     }
  126.     xturn = turns % 100;
  127.     if (turns < 8)
  128.     xturn = 8;
  129.     if (h == 0)
  130.     return;
  131.     /* this section prints out the objects at "loc"  */
  132.     for (k = 1; k <= OBJMAX; k++) {
  133.     p = obimpr[k];
  134.     if (!((k <= MOVMAX && obloc[k] != loc) ||
  135.           (k > MOVMAX && (obw3[k] != loc && obw4[k] != loc)) ||
  136.           (k == HPUCK && loc == 38 && marflg[1]))) {
  137.         r = (p / 8) % 8;
  138.         if (r >= 1) {
  139.         if ((p & 1) == 1)
  140.             speak(odistb[k] + r);
  141.         }
  142.         if (!(obpprp[k] / 2048 == 0 && k != ZROBOT))
  143.         xcontn(k);
  144.     } continue;
  145.     }
  146.     /* standing on something?  */
  147.     if (spcloc == 1)
  148.     speak(212);
  149.     if (spcloc == 2) {
  150.     if (dirty == 0)
  151.         speak(509);
  152.     else
  153.         speak(510);
  154.     }
  155.     /* is the wire lying on the ground */
  156.     nowir = 1;
  157.     for (i = 0; i < 6; i++) {
  158.     if (wirelc[i] == loc)
  159.         nowir = 0;
  160.     }
  161.     if (nowir == 0)
  162.     speak(215);
  163.  
  164.     if ((loc == 76 || loc == 77 || loc == 79) && obloc[ZCAT] ==
  165.     80)
  166.     speak(280);
  167.     /* flowers following sun  */
  168.     if (loc == 86 && xturn > 6 && xturn < 69 && obimpr[ZSEED] > 4000)
  169.     speak(341);
  170.     /* vine describe   */
  171.     if (loc == 74 && obimpr[ZVINE] == 9) {
  172.     speak(339);
  173.     obimpr[ZVINE] = 8201;
  174.     } else if (loc == 74 && obimpr[ZVINE] == 8201)
  175.     speak(259);
  176. }
  177.  
  178. vinven()
  179. /* "inventory"  */
  180. {
  181.     int             carryn, wearn, i, k;
  182.  
  183.     carryn = 0;
  184.     wearn = 0;
  185.     if (wirelc[5] == 1000)
  186.     carryn = 1;
  187.     for (i = 1; i <= MOVMAX; i++) {
  188.     if (obloc[i] == 1000)
  189.         carryn = 1;
  190.     if (obloc[i] == 3000)
  191.         wearn = 1;
  192.     }
  193.     if (carryn == 1) {
  194.     speak(62);
  195.         xindnt += 2;
  196.     if (wirelc[5] == 1000)
  197.         speak(256);
  198.     for (k = 1; k <= MOVMAX; k++) {
  199.         if (obloc[k] != 1000)
  200.         continue;
  201.         speak(odistb[k]);
  202.         if (obpprp[k] / 2048 != 0)
  203.         xcontn(k);
  204.     }
  205.         xindnt -= 2;
  206.     }
  207.     if (wearn == 1) {
  208.     speak(63);
  209.         xindnt += 2;
  210.     for (k = 1; k <= MOVMAX; k++) {
  211.         if (obloc[k] != 3000)
  212.         continue;
  213.         speak(odistb[k]);
  214.         if (obpprp[k] / 2048 != 0)
  215.         xcontn(k);
  216.     }
  217.         xindnt -= 2;
  218.     }
  219.     if (carryn == 0 && wearn == 0)
  220.     speak(64);
  221.     nonext = 1;
  222. }
  223.  
  224. xcontn(k)                             /* RECURSIVE FUNCTION */
  225.     int             k;
  226. {
  227.     int             p, empty, k1;
  228.     /*
  229.      * list contents of a container 
  230.      * calls itself recursively to list things inside other containers
  231.      */
  232.  
  233.     if (k == LFUNNE || k == MFUNNE || k == RFUNNE)
  234.     return;
  235.     p = obimpr[k];
  236.     if ((p & 2) == 0 || (obpprp[k] & 128) == 0) {
  237.     empty = 1;
  238.     for (k1 = 1; k1 <= MOVMAX; k1++)
  239.         if (obloc[k1] == k + 2000)
  240.         empty = 0;
  241.     if (empty) {
  242.         xindnt += 2;
  243.         speak(odistb[k] + ((p / 512) % 8));
  244.         xindnt -= 2;
  245.     } else {
  246.         xindnt += 2;
  247.         speak(odistb[k] + ((p / 512) % 8) + 1);
  248.         xindnt += 2;
  249.         for (k1 = 1; k1 <= MOVMAX; k1++) {
  250.         if (obloc[k1] == k + 2000) {
  251.             speak(odistb[k1]);
  252.                  if (obpprp[k1] / 2048 != 0)
  253.                 xcontn(k1);
  254.                 }
  255.         }
  256.         xindnt -= 4;
  257.     }
  258.     } else if ((p & 2) != 0 && (obpprp[k] & 128) != 0 && prepdo == IN)
  259.     speak(386);
  260. }
  261.  
  262. dbg()
  263. {
  264.     if(debugflg == 0) return;
  265.     debugflg = 2;
  266.     printf(" loc is %5d \n", loc);
  267.     printf(" enter new loc ");
  268.     scanf("%d", &loc);
  269. }
  270.  
  271. scorng()
  272. {
  273.     int             result, i, q, v, l, n, plce, xplc;
  274.     result = 0;
  275.     if (loc >= 153)
  276.     return (0);
  277.     result = (diesc - 3) * 2;
  278.     if (result < 0)
  279.     result = 0;
  280.     if (cactsc == 1 || cactsc == 2)
  281.     result += 2;
  282.     if (cactsc == 3)
  283.     result += 4;
  284.     if ((eastsc & 1) != 0)
  285.     result += 2;
  286.     if ((eastsc & 2) != 0)
  287.     result += 2;
  288.     if ((eastsc & 4) != 0)
  289.     result += 2;
  290.     if(debugflg == 2) 
  291.         printf(" east+cact %5d out of 10\n",result);
  292.     for (i = 1; i <= MOVMAX; i++) {
  293.     q = obw4[i];
  294.     v = q / 4096;
  295.     l = q - v * 4096;
  296.     if (v == 0)
  297.         continue;
  298.         n = 0;
  299.     itsher(i, &plce);
  300.     if (i == GDISC) {
  301.         if (plce != 0 && rvtim == 2)
  302.         n = v;
  303.     } else if (l >= 4000 && l - 4000 != obloc[i])
  304.         n = v;
  305.     else if (l == 3000 && obloc[i] == 3000)
  306.         n = v;
  307.     else if (l == 1000 && (plce == 1 || plce == 3))
  308.         n = v;
  309.     else if (l == 3000 && (plce == 1 || plce == 3))
  310.         n = v / 2;
  311.     else if (l < 1000 && l == obloc[i])
  312.         n = v;
  313.     else if (l > 2000 && l < 3000 && obloc[i] == l) {
  314.         itsher((l - 2000), &xplc);
  315.         if (xplc > 0 && xplc <= 3)
  316.         n = v;
  317.     }
  318.         result += n;
  319.         if(debugflg == 2)printf("obj %5d %5d points out of %5d\n",i,n,v);
  320.     }
  321.     if (deadf)
  322.     result -= 5;
  323.     if (result < 0)
  324.     result = 0;
  325.     result *= 5;
  326.     return (result);
  327. }
  328.  
  329. getrob(don, doa)
  330.     int             don, doa;
  331. {
  332.     int             result, i;
  333.     /*
  334.      * search table for object return object number if found and unambiguous
  335.      * return 0 if not found return -1 if ambiguous  
  336.      */
  337.  
  338.     for (i = 1; i <= OBJMAX; i++) {
  339.     if (don != obnoun[i])
  340.         continue;
  341.     if ((doa == abs(obadjv[i])) || (doa == 0 && obadjv[i] < 0))
  342.         return (i);
  343.     else if (doa == 0 && obadjv[i] > 0)
  344.         result = -1;
  345.     else
  346.         result = 0;
  347.     }
  348.     return (result);
  349. }
  350.  
  351.     static  char    sstring[] =
  352.     "Your score is     out of a total of     in      turns.";
  353.     static  int     breakp[] = {0, 35, 70, 90, 130, 170, 210, 260, 330,
  354.                 380, 450, 900};
  355. scorpt(scor, mxsc)
  356.     int             scor, mxsc;
  357. {
  358.     char            cnum[4];
  359.     int             i;
  360.  
  361.     numcvt(scor, cnum);
  362.     sstring[14] = cnum[1];
  363.     sstring[15] = cnum[2];
  364.     sstring[16] = cnum[3];
  365.     numcvt(mxsc, cnum);
  366.     sstring[36] = cnum[1];
  367.     sstring[37] = cnum[2];
  368.     sstring[38] = cnum[3];
  369.     numcvt(turns, cnum);
  370.     sstring[43] = cnum[0];
  371.     sstring[44] = cnum[1];
  372.     sstring[45] = cnum[2];
  373.     sstring[46] = cnum[3];
  374.     linout(sstring, 54);
  375.     for (i = 0; i < 10; i++) {
  376.     if (scor >= breakp[i] && scor < breakp[i + 1])
  377.         break;
  378.     }
  379.     speak(481 + i);
  380.  
  381. }
  382.  
  383. numcvt(num, cnum)
  384.     int             num;
  385.     char           *cnum;
  386. {
  387.     int             lx, m;
  388.  
  389.     m = num / 1000;
  390.     lx = (m) ? '0' + m : ' ';
  391.     *cnum++ = lx;
  392.     m = (num / 100) % 10;
  393.     lx = (m == 0 && lx == ' ') ? ' ' : '0' + m;
  394.     *cnum++ = lx;
  395.     m = (num / 10) % 10;
  396.     lx = (m == 0 && lx == ' ') ? ' ' : '0' + m;
  397.     *cnum++ = lx;
  398.     m = num % 10;
  399.     *cnum = '0' + m;
  400. }
  401.  
  402. robdsc()
  403. {
  404.     int             rempty, lempty, k;
  405.  
  406.     if (obloc[ZROBOT] >= 90 && obloc[ZROBOT] <= 95)
  407.     speak(gtext[1] + obloc[ZROBOT]);
  408.     else
  409.     speak(226 + obloc[ZROBOT]);
  410.     rempty = 1;
  411.     lempty = 1;
  412.     for (k = 1; k <= MOVMAX; k++) {
  413.     if (obloc[k] == 2000 + ZROBOT)
  414.         rempty = 0;
  415.     if (obloc[k] == obloc[ZROBOT] && k != ZROBOT)
  416.         lempty = 0;
  417.     }
  418.     if (rempty == 0) {
  419.     speak(odistb[ZROBOT] + 5);
  420.     for (k = 1; k <= MOVMAX; k++) {
  421.         xindnt += 2;
  422.         if (obloc[k] == 2000 + ZROBOT)
  423.         speak(odistb[k]);
  424.         xindnt -= 2;
  425.     }
  426.     }
  427.     if (lempty == 0) {
  428.     speak(350);
  429.     for (k = 1; k <= MOVMAX; k++) {
  430.         xindnt += 2;
  431.         if (k != ZROBOT && obloc[k] == obloc[ZROBOT])
  432.         speak(odistb[k]);
  433.         xindnt -= 2;
  434.     }
  435.     }
  436.     if (obloc[ZROBOT] == 90 && (obloc[ZORCHI] == 2000 + ZROBOT
  437.                 || obloc[ZFLYTR] == 2000 + ZROBOT))
  438.     speak(353);
  439. }
  440.  
  441.  
  442. endsl()
  443. {
  444.     /* dummy routine to maybe clear screen? */
  445. }
  446.  
  447.  
  448. vdead()
  449. {
  450.     int             i;
  451.     /*
  452.      * "you're dead,fred" it is incumbent on the calling routine to get to
  453.      * where the body is supposed to lie, and to set oldloc and oldlc2 to
  454.      * ,usually, 0 this routine sets deadf to .true. and drops all his
  455.      * possessions where he is now 
  456.      */
  457.  
  458.     eattim = 0;
  459.     rdietm = 0;
  460.     deadf = 1;
  461.     for (i = 1; i <= MOVMAX; i++)
  462.     if (obloc[i] == 1000 || obloc[i] == 3000)
  463.         obloc[i] = loc;
  464.     if (loc < 153)
  465.     speak(55);
  466.     else
  467.     speak(552);
  468.     nonext = 1;
  469.     eolflg = 1;
  470.     spcloc = 0;
  471.     for (i = 0; i < 6; i++)
  472.     if (wirelc[i] == 1000)
  473.         wirelc[i] = loc;
  474.     if (wirelc[0] != obloc[ZWIRE])
  475.     return;
  476.     for (i = 0; i < 6; i++)
  477.     wirelc[i] = 0;
  478.     diesc += 1;
  479. }
  480.  
  481. itsher(objt, plce)
  482.     int             objt;
  483.     int            *plce;
  484. {
  485.     int             n1;
  486.     /*
  487.      * this subroutine tells if an object is either: being carried     plce=1
  488.      * being worn        plce=2 inside something being carried,and not hidden
  489.      * from view (3) at "loc" and not hidden  (4) inside something at loc (5) 
  490.      */
  491.  
  492.     *plce = 0;
  493.     if (objt <= MOVMAX) {
  494.     if (obloc[objt] == 1000)
  495.         *plce = 1;
  496.     else if (obloc[objt] == 3000)
  497.         *plce = 2;
  498.     else if (obloc[objt] == loc && (obimpr[objt] & 1) == 1)
  499.         *plce = 4;
  500.     else if (obloc[objt] > 2000 && obloc[objt] < 3000) {
  501.         n1 = obloc[objt] - 2000;
  502.         if (n1 <= MOVMAX) {
  503.         if ((obloc[n1] == 1000 || obloc[n1] == 3000)
  504.             && (obimpr[n1] & 2) == 0)
  505.             *plce = 3;
  506.         else if (obloc[n1] == loc && ((obimpr[n1] & 1) == 1)
  507.              && ((obimpr[n1] & 2) == 0))
  508.             *plce = 5;
  509.         else;
  510.         } else if ((obw3[n1] == loc || obw4[n1] == loc) &&
  511.                ((obimpr[n1] & 1) == 1) && ((obimpr[n1] & 2) == 0))
  512.         *plce = 5;
  513.         else;
  514.     } else;
  515.     } else if ((obw3[objt] == loc || obw4[objt] == loc) &&
  516.            ((obimpr[objt] & 1) == 1))
  517.     *plce = 4;
  518. }
  519.  
  520. burden(ncarrd, nweigh, kcarrd, kweigh)
  521.     int            *ncarrd, *nweigh, *kcarrd, *kweigh;
  522. {
  523.     int             i;
  524.     /*
  525.      * calculate weight and number of objects on adventurer and in knapsack  
  526.      */
  527.  
  528.  
  529.     *ncarrd = 0;
  530.     *nweigh = 0;
  531.     for (i = 1; i <= MOVMAX; i++) {
  532.     if (obloc[i] != 1000)
  533.         continue;
  534.     *ncarrd += 1;
  535.     *nweigh += obw3[i] / 256;
  536.     }
  537.     *kcarrd = 0;
  538.     *kweigh = 0;
  539.     for (i = 1; i <= MOVMAX; i++) {
  540.     if (i == ZKNAPS || obloc[i] != (2000 + ZKNAPS))
  541.         continue;
  542.     *kcarrd += 1;
  543.     *kweigh += obw3[i] / 256;
  544.     }
  545. }
  546.  
  547. getobj(don, doa)
  548.     int             don, doa;
  549. {
  550.     /*
  551.      * search table for object return object number if found and unambiguous
  552.      * return 0 if not found return -1 if ambiguous  
  553.      */
  554.  
  555.     int             result, i, g1, g2, ggg, ddd, sum;
  556.     int             aplce, bplce, cplce, dplce, fplce, gplce, mplce, nplce, oplce, pplce;
  557.     int             splce, tplce;
  558.     result = 0;
  559.     for (i = 1; i <= OBJMAX; i++) {
  560.  
  561.     if (don != obnoun[i])
  562.         continue;
  563.     if ((doa == abs(obadjv[i]) && doa != BEAUTI && doa !=
  564.          VENDIN) || (doa == 0 && obadjv[i] < 0)) {
  565.         result = i;
  566.         return (result);
  567.     } else if ((doa == 0 && obadjv[i] > 0) || (doa == VENDIN &&
  568.              don == MACHIN) || (doa == BEAUTI && don == BIRD)) {
  569.         if (don == FISH) {
  570.         if (obloc[CFISH] != 0)
  571.             result = CFISH;
  572.         else
  573.             result = DFISH;
  574.         } else if (don == PANTS) {
  575.         itsher(RPANT, &g1);
  576.         itsher(LPANT, &g2);
  577.         if (g1 != 0 && g2 == 0)
  578.             result = RPANT;
  579.         else if (g1 == 0 && g2 != 0)
  580.             result = LPANT;
  581.         else if ((wrdnum[0] == TAKE && prepdo == OFF) ||
  582.              wrdnum[0] == REMOVE) {
  583.             if (g1 == 2)
  584.             result = RPANT;
  585.             else
  586.             result = LPANT;
  587.         } else if (wrdnum[0] == DROP) {
  588.             if (((g1 == 1) || (g1 == 3)) && g2 != 1 && g2 != 3)
  589.             result = RPANT;
  590.             if (((g2 == 1) || (g2 == 3)) && g1 != 1 && g1 != 3)
  591.                 result = LPANT;
  592.         } else
  593.             result = -1;
  594.         } else if (don == SHIRT) {
  595.         itsher(RSHIRT, &g1);
  596.         itsher(GSHIRT, &g2);
  597.         if (g1 != 0 && g2 == 0)
  598.             result = RSHIRT;
  599.         else if (g1 == 0 && g2 != 0)
  600.             result = GSHIRT;
  601.         else if ((wrdnum[0] == TAKE && prepdo == OFF) ||
  602.              wrdnum[0] == REMOVE) {
  603.             if (g1 == 2)
  604.             result = RSHIRT;
  605.             else
  606.             result = GSHIRT;
  607.         } else if (wrdnum[0] == DROP) {
  608.             if (((g1 == 1) || (g1 == 3)) && g2 != 1 && g2 != 3)
  609.             result = RSHIRT;
  610.             if (((g2 == 1) || (g2 == 3)) && g1 != 1 && g1 != 3)
  611.             result = GSHIRT;
  612.         } else
  613.             result = -1;
  614.         } else if (don == DOOR) {
  615.         if (loc == 41 || loc == 135)
  616.             result = MDOOR;
  617.         else if (loc == 85 || loc == 136)
  618.             result = GDOOR;
  619.         else if (loc == 47 || loc == 51)
  620.             result = RDOOR;
  621.         else if (loc == 165 || loc == 166)
  622.             result = ODOOR;
  623.         else if (loc == 173)
  624.             result = PDOOR;
  625.         else if (loc == 175)
  626.             result = BDOOR;
  627.         else
  628.             result = -1;
  629.         } else if (don == CARTRI) {
  630.         itsher(ZCART, &tplce);
  631.         itsher(CCART, &cplce);
  632.         if (tplce > 0 && cplce <= 0)
  633.             result = ZCART;
  634.         else if (tplce <= 0 && cplce > 0)
  635.             result = CCART;
  636.         else
  637.             result = -1;
  638.         } else if (don == PHOTOG) {
  639.         itsher(PPHOTO, &pplce);
  640.         itsher(MPHOTO, &mplce);
  641.         itsher(OPHOTO, &oplce);
  642.         itsher(APHOTO, &aplce);
  643.         itsher(FPHOTO, &fplce);
  644.         pplce = (pplce < 1) ? pplce : 1;
  645.         mplce = (mplce < 1) ? mplce : 1;
  646.         oplce = (oplce < 1) ? oplce : 1;
  647.         aplce = (aplce < 1) ? aplce : 1;
  648.         fplce = (fplce < 1) ? fplce : 1;
  649.         sum = pplce + mplce + oplce + aplce + fplce;
  650.         {
  651.             if (sum == 0)
  652.             result = 0;
  653.             else if (sum > 1)
  654.             result = -1;
  655.             else {
  656.             if (pplce != 0)
  657.                 result = PPHOTO;
  658.             if (mplce != 0)
  659.                 result = MPHOTO;
  660.             if (oplce != 0)
  661.                 result = OPHOTO;
  662.             if (aplce != 0)
  663.                 result = APHOTO;
  664.             if (fplce != 0)
  665.                 result = FPHOTO;
  666.             }
  667.         }
  668.         } else if (don == BIRD) {
  669.         if (loc == 65 || loc == 66)
  670.             result = RBIRD;
  671.         else if (loc == 78 || loc == 79)
  672.             result = XBIRD;
  673.         else if (loc == 77 || loc == 80)
  674.             result = YBIRD;
  675.         else if (loc == 75 || loc == 76)
  676.             result = ZBIRD;
  677.         else
  678.             result = 0;
  679.         } else if (don == BUTTON) {
  680.         if (loc == 146 || loc == 134)
  681.             result = -1;
  682.         else if (loc == 143)
  683.             result = RDBUTT;
  684.         else if (loc == 169)
  685.             result = GBUTTO;
  686.         else
  687.             result = 0;
  688.         } else if (don == CABLE || don == DISC) {
  689.         if (don == CABLE) {
  690.             ddd = DCABLE;
  691.             ggg = GCABLE;
  692.         } else {
  693.             ddd = BDISC;
  694.             ggg = GDISC;
  695.         }
  696.         itsher(ddd, &dplce);
  697.         itsher(ggg, &gplce);
  698.         if (dplce == 0 && gplce == 0)
  699.             result = 0;
  700.         else {
  701.             if (wrdnum[0] == DROP) {
  702.             if ((dplce == 1 || dplce == 3) && (gplce != 1 
  703.                                                                  && gplce != 3))
  704.                 result = ddd;
  705.             else if ((gplce == 1 || gplce == 3) && 
  706.                                                      (dplce != 1 && dplce != 3))
  707.                 result = ggg;
  708.             else
  709.                 result = -1;
  710.             } else if (wrdnum[0] == TAKE) {
  711.             if ((dplce == 4 || dplce == 5) && (gplce != 4 
  712.                                                                  && gplce != 5))
  713.                 result = ddd;
  714.             else if ((gplce == 4 || gplce == 5) &&
  715.                                                      (dplce != 4 && dplce != 5))
  716.                 result = ggg;
  717.             else
  718.                 result = -1;
  719.             } else {
  720.             if (gplce == 0 && dplce != 0)
  721.                 result = ddd;
  722.             else if (dplce == 0 && gplce != 0)
  723.                 result = ggg;
  724.             else
  725.                 result = -1;
  726.             }
  727.         }
  728.         } else if (don == MACHIN) {
  729.         if (loc == 153)
  730.             result = PMACH;
  731.         else if (loc == 156)
  732.             result = TMACH;
  733.         else if (loc == 158)
  734.             result = NMACH;
  735.         else if (loc == 160)
  736.             result = SMACH;
  737.         else if (loc == 162)
  738.             result = MMACH;
  739.         } else if (don == SLOT) {
  740.         if (loc == 146)
  741.             result = RSLOT;
  742.         else if (loc == 156)
  743.             result = TSLOT;
  744.         else if (loc == 158)
  745.             result = NSLOT;
  746.         else if (loc == 160)
  747.             result = SSLOT;
  748.         else if (loc == 162)
  749.             result = MSLOT;
  750.         } else if (don == COIN) {
  751.         if (loc < 153)
  752.             result = SCOIN;
  753.         else {
  754.             itsher(SCOIN, &splce);
  755.             itsher(BCOIN, &bplce);
  756.             itsher(CCOIN, &cplce);
  757.             itsher(NCOIN, &nplce);
  758.             itsher(PCOIN, &pplce);
  759.             pplce = (pplce < 1) ? pplce : 1;
  760.             nplce = (nplce < 1) ? nplce : 1;
  761.             cplce = (cplce < 1) ? cplce : 1;
  762.             bplce = (bplce < 1) ? bplce : 1;
  763.             splce = (splce < 1) ? splce : 1;
  764.             sum = pplce + nplce + cplce + bplce + splce;
  765.             if (sum == 0)
  766.             result = 0;
  767.             else if (sum > 1)
  768.             result = -1;
  769.             else {
  770.             if (splce != 0)
  771.                 result = SCOIN;
  772.             if (bplce != 0)
  773.                 result = BCOIN;
  774.             if (cplce != 0)
  775.                 result = CCOIN;
  776.             if (nplce != 0)
  777.                 result = NCOIN;
  778.             if (pplce != 0)
  779.                 result = PCOIN;
  780.             }
  781.         }
  782.         } else
  783.         result = -1;
  784.         return (result);
  785.     }
  786.     }
  787.     return (result);
  788. }
  789.     static  char    strng1[] = "    I can't do that to item    on your list.";
  790.     static  char    strng2[] = "    Item number    on your list is ambiguous";
  791.  
  792. cnvobj()
  793. {
  794.     char            cnum[4];
  795.     int             result, many, i, k, n, p, z;
  796.  
  797.     /*
  798.      * this routine searches the list of objects and compares with the list
  799.      * of d.o.'s if an object exists and is unambiguous it's entry in dobjs
  800.      * is replaced by its object number otherwise its entry in dobjs is set
  801.      * to zero the entries in dobsj are then squeezed up if the result was
  802.      * totally unambiguous cnvobj is .true. 
  803.      */
  804.  
  805.     result = 1;
  806.     n = 0;
  807.     if (allflg)
  808.     n = 1;
  809.     many = 0;
  810.     if ((butflg && dobjs[2] != 0) || ((!butflg) &&
  811.                       dobjs[1] != 0))
  812.     many = 1;
  813.     k = 0;
  814.     z = -1;
  815.     for (i = n; i < 12; i++) {
  816.     k += 1;
  817.     if (dobjs[i] == 0)
  818.         break;
  819.     p = getobj(dobjs[i], doadjs[i]);
  820.     if (p > 0) {
  821.         z += 1;
  822.         dobjs[z] = p;
  823.     } else if (p == 0) {
  824.         if (many == 1) {
  825.         numcvt(k, cnum);
  826.         strng1[28] = cnum[2];
  827.         strng1[29] = cnum[3];
  828.         linout(strng1, 44);
  829.         } else
  830.         speak(422);
  831.     } else {
  832.         result = 0;
  833.         if (many == 1) {
  834.         numcvt(k, cnum);
  835.         strng2[16] = cnum[2];
  836.         strng2[17] = cnum[3];
  837.         linout(strng2, 44);
  838.         } else
  839.         speak(70);
  840.         speak(250);
  841.     }
  842.     }
  843.     while (++z < 30)
  844.     dobjs[z] = 0;
  845.     return (result);
  846. }
  847.  
  848. getall()
  849. {
  850.  
  851.     int             temp[30], i, k, d, m;
  852.     /*
  853.      * routine to get "all" or "all but" objects it only works on moveable
  854.      * objects because the only verbs which call it work only on those
  855.      * objects (drop,take, put) 
  856.      */
  857.  
  858.     for (i = 0; i < 30; i++) {
  859.     temp[i] = dobjs[i];
  860.     dobjs[i] = 0;
  861.     }
  862.     k = 0;
  863.     for (i = 1; i <= MOVMAX; i++) {
  864.     itsher(i, &d);
  865.     if (d == 0)
  866.         continue;
  867.     for (m = 0; m < 30; m++)
  868.         if (temp[m] == i)
  869.         goto endloop;
  870.     if (k == 29) {
  871.         speak(106);
  872.         return;
  873.     }
  874.     dobjs[k++] = i;
  875. endloop:
  876.     ;
  877.     }
  878. }
  879.  
  880.  
  881. rdinit()
  882. {
  883.     long            t;
  884.     long            tloc;
  885.     long            time();
  886.     int             ti;
  887.     t = time(&tloc);
  888.     ti =( (int) t) & 32767;
  889.     srand(ti);
  890. }
  891.  
  892. qrand()
  893. {
  894.     return ((rand() & 16383) / 4);
  895. }
  896.  
  897.  
  898. pct(q)
  899.     int             q;
  900. {
  901.     int             j;
  902.  
  903.     j = rand();
  904.     return ((q * 327) > (j & 32767));
  905. }
  906.  
  907. extern char *gets();
  908.  
  909. yesx(spk)
  910.     int             spk;
  911. {
  912.     char *eoferr;
  913.     char            ans[90];
  914.     /* ask question, and wait for reply from him */
  915.  
  916.  
  917.     speak(spk);
  918.     more = 0;
  919.     while (1) {
  920.     linout("?", 2001);
  921.     eoferr = gets(ans);
  922.     more = 1;
  923.     if (strcmp(ans, "Y") == 0 || strcmp(ans, "YES") == 0
  924.         || strcmp(ans, "y") == 0 || strcmp(ans, "yes") == 0
  925.             || eoferr == (char *) 0)
  926.         return (1);
  927.     else if (strcmp(ans, "N") == 0 || strcmp(ans, "NO") == 0
  928.          || strcmp(ans, "n") == 0 || strcmp(ans, "no") == 0)
  929.         return (0);
  930.     else
  931.         speak(102);
  932.     }
  933. }
  934.  
  935. getln()
  936. {
  937.     /* write a prompt, then read a line from the terminal */
  938.  
  939.     char *eoferr;
  940.     int             i, lastpos;
  941.     linout(">", 7001);
  942.  
  943.     eoferr = gets(inbuf);
  944.     if(eoferr == (char *) 0) exit(0);
  945.     eolflg = 0;
  946.     lastpos = strlen(inbuf);
  947.     lastpos = (lastpos > 78) ? 78 : lastpos;
  948.     for (i = lastpos; i < 83; i++)
  949.     inbuf[i] = '.';
  950.     more = 1;
  951.     inbuf[127] = lastpos;
  952. }
  953.  
  954.  
  955. carerr(x, z)
  956.     int             x, z;
  957. {
  958.     /*
  959.      * this nifty routine put a caret on the terminal at the indicated
  960.      * position of a line and then outputs a message  
  961.      */
  962.     /* if not the first sentence on a line, rewrite line.  */
  963.  
  964.     if (clause != 1) {
  965.     linout(" ", 1001);
  966.     linout(inbuf, inbuf[127]);
  967.     }
  968.     if (x > 0) {
  969.     xindnt = x;
  970.     linout("^", 1);
  971.     xindnt = 0;
  972.     } else {
  973.     if (clause != 1) {
  974.         xindnt = lptr - 1;
  975.         linout("*", 1);
  976.         xindnt = 0;
  977.         speak(423);
  978.     }
  979.     }
  980.     speak(z);
  981. }
  982.  
  983. linout(ustring, num)
  984.     char           *ustring;
  985.     int             num;
  986.  
  987. {
  988.     int             num1, i;
  989.     char            buff[80];
  990.     char           *cptr;
  991.  
  992.     cptr = buff;
  993.     num1 = num % 1000;
  994.     for (i = 0; i < xindnt; i++)
  995.     *cptr++ = ' ';
  996.  
  997.     for (i = 0; i < num1; i++)
  998.     *cptr++ = *ustring++;
  999.  
  1000.     *cptr++ = '\0';
  1001.     if (num < 1000) {
  1002.         if(more == 19 && nomor == 0) {
  1003.             i = strlen(buff);
  1004.             for( ; i < 74; i++)
  1005.                buff[i] = ' '; 
  1006.             strcpy(&buff[74],"MORE");
  1007.             printf("%1s", buff);
  1008.             gets(buff);
  1009.             more = 0;
  1010.         }
  1011.         else {
  1012.             printf("%1s\n", buff);
  1013.             more += 1;
  1014.         }
  1015.     }
  1016.     else
  1017.     printf("%1s", buff);
  1018. }
  1019.  
  1020.  
  1021. vsuspe(inout)
  1022.     int             inout;
  1023. {
  1024.     short            sbuffer[256];
  1025.     int             result, filedes, i, iret;
  1026.     short           *sbptr, *iptr;
  1027.     result = 0;
  1028.  
  1029.     if (inout != 1) {
  1030.     /* "suspend" or "save"  */
  1031.  
  1032.     filedes = creat(filenm, 0600);
  1033.     if (filedes == -1) {
  1034.         linout("I failed to create your save file.", 34);
  1035.         return (result);
  1036.     }
  1037.     sbptr = sbuffer;
  1038.     *sbptr++ = horflg;
  1039.     for (i = 0; i < 6; i++)
  1040.         *sbptr++ = wirelc[i];
  1041.     *sbptr++ = turns;
  1042.     *sbptr++ = loc;
  1043.     *sbptr++ = oldloc;
  1044.     *sbptr++ = oldlc2;
  1045.     *sbptr++ = brfflg;
  1046.     *sbptr++ = deadf;
  1047.     *sbptr++ = dirty;
  1048.     *sbptr++ = nonext;
  1049.     *sbptr++ = spcloc;
  1050.     *sbptr++ = fshlif;
  1051.     *sbptr++ = noshoe;
  1052.     *sbptr++ = daytim;
  1053.     *sbptr++ = martim;
  1054.     for (i = 0; i < 9; i++)
  1055.         *sbptr++ = marflg[i];
  1056.     *sbptr++ = oextim;
  1057.     *sbptr++ = rdietm;
  1058.     *sbptr++ = rvtim;
  1059.     *sbptr++ = gvtim;
  1060.     *sbptr++ = eattim;
  1061.     *sbptr++ = easttm;
  1062.     *sbptr++ = filmtm;
  1063.     *sbptr++ = screef;
  1064.     *sbptr++ = eastsc;
  1065.     *sbptr++ = cactsc;
  1066.     *sbptr++ = diesc;
  1067.     *sbptr++ = filmst;
  1068.     *sbptr++ = machst;
  1069.     *sbptr++ = dial1;
  1070.     *sbptr++ = dial2;
  1071.     *sbptr++ = dial1x;
  1072.     *sbptr++ = dial2x;
  1073.     *sbptr++ = bonus;
  1074.     *sbptr++ = jackpo;
  1075.     *sbptr++ = lpill;
  1076.     *sbptr++ = pbstat;
  1077.     *sbptr++ = decset;
  1078.     *sbptr++ = raset;
  1079.     *sbptr++ = dcombi;
  1080.     *sbptr++ = chaset;
  1081.     *sbptr++ = guardl;
  1082.         *sbptr++ = fimage;
  1083.     write(filedes, sbuffer, 64*sizeof(short));
  1084.     sbptr = sbuffer;
  1085.     iptr = locdat;
  1086.     for (i = 0; i <= LOCNUM; i++)
  1087.         *sbptr++ = *iptr++;
  1088.     write(filedes, sbuffer, 256*sizeof(short));
  1089.     sbptr = sbuffer;
  1090.     iptr = obimpr;
  1091.     for (i = 0; i <= OBJMAX; i++)
  1092.         *sbptr++ = *iptr++;
  1093.     write(filedes, sbuffer, 256*sizeof(short));
  1094.     sbptr = sbuffer;
  1095.     iptr = obloc;
  1096.     for (i = 0; i <= OBJMAX; i++)
  1097.         *sbptr++ = *iptr++;
  1098.     write(filedes, sbuffer, 256*sizeof(short));
  1099.     close(filedes);
  1100.     return (result);
  1101.     } else {
  1102.     /* "restore"    */
  1103.  
  1104.     filedes = open(filenm, 0);
  1105.     if (filedes == -1)
  1106.         goto lab1;
  1107.     iret = read(filedes, sbuffer, 64*sizeof(short));
  1108.     if (iret != 64*sizeof(short))
  1109.         goto lab1;
  1110.     sbptr = sbuffer;
  1111.     horflg = *sbptr++;
  1112.     for (i = 0; i < 6; i++)
  1113.         wirelc[i] = *sbptr++;
  1114.     turns = *sbptr++;
  1115.     loc = *sbptr++;
  1116.     oldloc = *sbptr++;
  1117.     oldlc2 = *sbptr++;
  1118.     brfflg = *sbptr++;
  1119.     deadf = *sbptr++;
  1120.     dirty = *sbptr++;
  1121.     nonext = *sbptr++;
  1122.     spcloc = *sbptr++;
  1123.     fshlif = *sbptr++;
  1124.     noshoe = *sbptr++;
  1125.     daytim = *sbptr++;
  1126.     martim = *sbptr++;
  1127.     for (i = 0; i < 9; i++)
  1128.         marflg[i] = *sbptr++;
  1129.     oextim = *sbptr++;
  1130.     rdietm = *sbptr++;
  1131.     rvtim = *sbptr++;
  1132.     gvtim = *sbptr++;
  1133.     eattim = *sbptr++;
  1134.     easttm = *sbptr++;
  1135.     filmtm = *sbptr++;
  1136.     screef = *sbptr++;
  1137.     eastsc = *sbptr++;
  1138.     cactsc = *sbptr++;
  1139.     diesc = *sbptr++;
  1140.     filmst = *sbptr++;
  1141.     machst = *sbptr++;
  1142.     dial1 = *sbptr++;
  1143.     dial2 = *sbptr++;
  1144.     dial1x = *sbptr++;
  1145.     dial2x = *sbptr++;
  1146.     bonus = *sbptr++;
  1147.     jackpo = *sbptr++;
  1148.     lpill = *sbptr++;
  1149.     pbstat = *sbptr++;
  1150.     decset = *sbptr++;
  1151.     raset = *sbptr++;
  1152.     dcombi = *sbptr++;
  1153.     chaset = *sbptr++;
  1154.     guardl = *sbptr++;
  1155.         fimage = *sbptr++;
  1156.     iret = read(filedes, sbuffer, 256*sizeof(short));
  1157.     if (iret != 256*sizeof(short))
  1158.         goto lab1;
  1159.     sbptr = sbuffer;
  1160.     iptr = locdat;
  1161.     for (i = 0; i <= LOCNUM; i++)
  1162.         *iptr++ = *sbptr++;
  1163.     iret = read(filedes, sbuffer, 256*sizeof(short));
  1164.     if (iret != 256*sizeof(short))
  1165.         goto lab1;
  1166.     sbptr = sbuffer;
  1167.     iptr = obimpr;
  1168.     for (i = 0; i <= OBJMAX; i++)
  1169.         *iptr++ = *sbptr++;
  1170.     iret = read(filedes, sbuffer, 256*sizeof(short));
  1171.     if (iret != 256*sizeof(short))
  1172.         goto lab1;
  1173.     sbptr = sbuffer;
  1174.     iptr = obloc;
  1175.     for (i = 0; i <= OBJMAX; i++)
  1176.         *iptr++ = *sbptr++;
  1177.         close(filedes);
  1178.     result = 1;
  1179.     chaser = 0;
  1180.     linout(" ", 1);
  1181.     return (result);
  1182.     }
  1183. lab1:
  1184.     linout("Restore failed.", 15);
  1185.     return (result);
  1186. }
  1187.  
  1188.